import { IFeidaoAiWeappPage } from '@dfeidao/atom-wxapp/interfaces';
import nodejs from '@dfeidao/atom-wxapp/msg/nodejs';
import render from '@dfeidao/atom-wxapp/render/render';
import get_local from '@dfeidao/atom-wxapp/local/get';
import set_local from '@dfeidao/atom-wxapp/local/set';
import show_toast from '@dfeidao/atom-wxapp/api/interaction/show-toast';
import show_loading from '@dfeidao/atom-wxapp/api/interaction/show-loading';
import hide_loading from '@dfeidao/atom-wxapp/api/interaction/hide-loading';

// import { send_msg as url } from '../atom/config';

export default async function a003(fd: IFeidaoAiWeappPage, ...args: any[]) {
	// todo
	const page_no = get_local<number>(fd, 'page_no');//12

	try {
		const data = await nodejs<any[]>('app-equipment-find', {
			asc: ['equip_no'],
			page_size: 2,
			page_no: page_no + 1//23
		});
		if (data.length > 0) {
			console.log(data, '-----------下一页数据----------');
			const list_data = get_local(fd, 'list_data') as any[];
			render(fd, { data: list_data.concat(data) });
			set_local(fd, 'page_no', page_no + 1);//23
			set_local(fd, 'list_data', list_data.concat(data));
		} else {
			show_toast('没有更多数据啦', 'none');
		}
	} catch (error) {
		show_loading('读取数据失败');
		hide_loading();
	}
}
